#encoding:utf-8
import os,sys
import web
import json,ast
import types
from PIL import Image
import base64


current_version = '20160912-1'


render = web.template.render('templates/')

urls = ('/', 'index',
        '/json/type=(.*?)', 'json',
        # '/getdata/(.*?)', 'getScheduleData',
        # '/getresource/id=(.*?)-resource.js', 'getScheduleDataImages',
        # '/version', 'getVersion',
        # '/print?(.*?)','printPdf',
        '/favicon.ico','Icon'
        )
app = web.application(urls, globals())

def cur_file_dir():
    path = sys.path[0]
    if os.path.isdir(path):
        return path
    elif os.path.isfile(path):
        return os.path.dirname(path)

home_dir = cur_file_dir()

class Icon:
    def GET(self):
        raise web.seeother("/static/res/favicon.ico")

class index:
    def GET(self):
        return render.swimlanes()
    def POST(self):
        return "hello"

class json:
    def GET(self,type):
        data = ""
        unicoded_path = ""
        if type == "01" :
            unicoded_path = "data\\01.searchProjectStageInfoList.do"
        elif type == "02" :
            unicoded_path = "data\\02.searchDepartmentInfoListByProjectID.do"
        elif type == "03" :
            unicoded_path = "data\\03.searchProjectDocumentInfoList.do"
        elif type == "04" :
            unicoded_path = "data\\04.searchProjectInfoList.do"
        #unicoded_path = os.path.join(home_dir.encode("utf-8"),unicoded_path)
        #print(unicoded_path)
        f = open(unicoded_path, "r")
        data = f.read()
        f.close()
        print(data)
        return data#json.dumps(data.encode("utf-8"))

if __name__=="__main__":
    web.internalerror = web.debugerror
    app.run()

    #application=app.wsgifunc()
